<?php
namespace StarCloud\Services;

use StarCloud\Library\Exception;

class QueueService extends BaseService
{
    const TUBE_FIRST_QUEUE = 'first_queue';
    const TUBE_BACKEND_CSV_FILE_EXPORT = 'backend_csv_file_export';
    const TUBE_BACKEND_COMPANY_USER_IMPORT_FILE = 'company_user_import_file';
    const TUBE_BACKEND_EXAM_QUESTION_IMPORT_FILE = 'exam_question_import_file';
    const TUBE_STUDY_TASK_INIT_USER = 'study_task_init_user';
    const TUBE_INTO_VIDEO_HEADER = 'into_video_header';

    const TUBE_USER_OPERATOR_LOG = 'user_operator_log';

    const  TUBE_LIST = [
        self::TUBE_FIRST_QUEUE,
        self::TUBE_BACKEND_CSV_FILE_EXPORT,
        self::TUBE_BACKEND_COMPANY_USER_IMPORT_FILE,
        self::TUBE_BACKEND_EXAM_QUESTION_IMPORT_FILE,
        self::TUBE_STUDY_TASK_INIT_USER,
        self::TUBE_INTO_VIDEO_HEADER,
        self::TUBE_USER_OPERATOR_LOG,
    ];

    // 实时消费队列
    public static function putToTuBe($queueName, array $params, $options = null)
    {
        if (!in_array($queueName, self::TUBE_LIST)) {
            throw new Exception(10017);
        }

        self::getQueue()->putToTube(
            $queueName,
            json_encode($params),
            $options
        );
    }
}
